<?php
ini_set('display_errors', 1);
error_reporting(E_ALL &~ E_NOTICE);
set_time_limit(0);

header("Content-type:text/html; charset=utf-8");
header("Expires: Mon, 26 Jul 1970 05:00:00 GMT"); 
header("Last-Modified: ".gmdate('D, d M Y H:i:s')." GMT");
header("Cache-control: no-cache, must-revalidate");
header("Pragma: no-cache");

unset($GLOBALS);
$_ENV = array();

define("PO_PATH",dirname(__FILE__));
define("CORE_PATH",PO_PATH."/source");
define('CACHE_PATH',PO_PATH.'/source/cache/');
define('ATTACH_PATH',PO_PATH.'/attach/');

define('IN_SYSTEM',1);

define('POST',strtolower($_SERVER['REQUEST_METHOD']) === 'post');
define('AJAX',(strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest') OR $_GET['inajax'] == '1');
define('REFER',$_SERVER['HTTP_REFERER']);
define('AUTH_KEY','this is custom auth secret key'.$_SERVER['HTTP_USER_AGENT']);


date_default_timezone_set('PRC');

$_ENV['time'] = time();


/*核心类列表*/
$list = include PO_PATH.'/include/core.php';
// 加载核心文件列表
foreach ($list as $key=>$file)
{
  if(is_file($file))  require $file;
}

/**
 * 加载全局配置文件
 */
$config = array();
@include PO_PATH.'/source/config.global.php';
$_ENV['config'] =  $config;

define('FORMHASH',formhash());

/**
 * 配置系统
 */
spl_autoload_register('import');


/**
 * 连接数据库
 */
$_ENV['db'] = new class_db($_ENV['config']['db']['host'],$_ENV['config']['db']['user'],$_ENV['config']['db']['pass'],$_ENV['config']['db']['name']);



/**
 * 加载系统设置
 */
$config = array();
if (class_cache::has('config')) {
    $config = class_cache::read('config');
} else {
    $rowset = $_ENV['db']->fetchAll("SELECT * FROM `setting`");
    foreach ((array)$rowset as $row) {
        $config[$row['k']] = $row['v'];
    }
    class_cache::write('config',$config);
}
$_ENV['config'] = array_merge($_ENV['config'],$config);
unset($config);
?>